package com.sun.androidexerciseproject.function.task;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.birbit.android.jobqueue.AsyncAddCallback;
import com.birbit.android.jobqueue.JobManager;
import com.birbit.android.jobqueue.config.Configuration;
import com.birbit.android.jobqueue.log.CustomLogger;
import com.sun.androidexerciseproject.function.R;

public class TaskTestActivity extends AppCompatActivity {
    private JobManager mJobManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_test);
        createJobManager();
    }

    public void start(View view) {
        for (int i = 0; i < 10; i++) {
            mJobManager.addJobInBackground(new MyJob("" + i), new AsyncAddCallback() {
                @Override
                public void onAdded() {
                    Log.d("MyJob", "onAdded ");
                }
            });
        }
    }

    private void createJobManager() {
        Configuration configuration = new Configuration.Builder(this)
                .customLogger(new CustomLogger() {
                    @Override
                    public boolean isDebugEnabled() {
                        return true;
                    }

                    @Override
                    public void d(String text, Object... args) {

                    }

                    @Override
                    public void e(Throwable t, String text, Object... args) {

                    }

                    @Override
                    public void e(String text, Object... args) {

                    }

                    @Override
                    public void v(String text, Object... args) {

                    }
                })
                .minConsumerCount(1)
                .maxConsumerCount(3)
                .loadFactor(3)
                .consumerKeepAlive(60)
                .build();
        mJobManager = new JobManager(configuration);
    }
}
